<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<SCRIPT type="text/javascript" src="commons/dojo.js"></SCRIPT>
<SCRIPT type="text/javascript" src="commons/json.js"></SCRIPT>
<link rel="stylesheet" type="text/css" href="styles/css/global.css">
<script type="text/javascript">

	var table= document.getElementById("addFormTable");
	function addSchool(){
	var table= document.getElementById("addFormTable");
		var   newrow   =   table.insertRow(4);
		var   newcell1   =   newrow.insertCell();  
		newcell1.innerHTML=div1.innerHTML;
		var   newcell2   =   newrow.insertCell();  
		newcell2.innerHTML=div2.innerHTML;
		var sid = document.getElementById("guest.otherSchoolId");
		changeSchoolList(sid);
	}
	function deleteSchool(src){
	var table= document.getElementById("addFormTable");
  		var   i=table.rows.length;   
  		while(i--){
  		//	 alert(i);   
 			 if(src==table.rows[i]){   
 			//	 alert("就是这行----"+   i);   
 			 	table.deleteRow(i);   
  			}   
  		}  
	}
	var div7Show=false;
	function changeRow(){
	//	alert(div7Show);
		var divShow=document.getElementById("div7");
	//	alert(divShow);
		var type = document.getElementById("guest.signType");
		var selectValue = type.options[type.selectedIndex].value;
		if(selectValue!=0 && div7Show == false){
			div7Show=true;
			var table= document.getElementById("addFormTable");
			var   newrow   =   table.insertRow(table.rows.length-3);
			var   newcell1   =   newrow.insertCell();  
			newcell1.innerHTML=div7.innerHTML;
			var   newcell2   =   newrow.insertCell();  
			newcell2.innerHTML=div8.innerHTML;
		}if(selectValue==0 && div7Show == true){
			var table= document.getElementById("addFormTable");
			table.deleteRow(table.rows.length-4);
			div7Show=false;
		}
	}
	var request;
	function test(){
		var lt_select = document.getElementById("guest.lessonTypeId");
	//	alert(ltid.options[ltid.selectedIndex].value);
		createRequest();
        var url = "ajax.do?lessonTypeId="+lt_select[lt_select.selectedIndex].value;
       request.open("POST", url, true);
       request.setRequestHeader("Content-Type", 
                       "application/x-www-form-urlencoded");
       request.onreadystatechange = updatePage;            
       request.send(null);	
	}
	function createRequest(){
		try {
  			request = new XMLHttpRequest();
		} catch (trymicrosoft) {
  			try {
    			request = new ActiveXObject("Msxml2.XMLHTTP");
 			 } catch (othermicrosoft) {
    			try {
     			 	request = new ActiveXObject("Microsoft.XMLHTTP");
   				 } catch (failed) {
      				request = false;
   		 		}
  			}
		}
		if (!request)
  			alert("Error initializing XMLHttpRequest!");
	}
	var schooljson
	function updatePage() {
     if (request.readyState == 4) {
       if (request.status == 200) {
         var response = request.responseText;
         //var shooljson =request.responseText.parseJSON();
         schooljson = eval('('  +  response  +  ')');
        var sid = document.getElementById("guest.schoolId");
		changeSchoolList(sid);
       // alert("over");
       } else
         alert("status is " + request.status);
     }
   }
   
   function changeSchoolList(select){
        // for(i=0;i<sid.length;i++){
        // 	sid.remove(sid.options[i]);
        // }
         select.options.length = 0 ;
         for(var i in schooljson){
         	var sc = schooljson[i];
         	var tempoption =document.createElement("OPTION");
         	tempoption.value=i;
         	tempoption.text=sc;
         	try{
         	    select.add(tempoption,null);
         	}catch(ex){
         		select.add(tempoption);
         	}
         }
   }
	
</script>
<script type="text/javascript">
		dojo.require("dojo.widget.validate");
	 function submitCheck(){
	 	 if (guestForm.all("guest.name").value.length<1){
			      alert('“名 称”不能为空！');
			      return false;
		}
		if (guestForm.all("guest.tel").value.length<1){
			      alert('“电 话”不能为空！');
			      return false;
		}
		if (guestForm.all("guest.lesson").value.length<1){
			      alert('“课 程”不能为空！');
			      return false;
		}
		if (guestForm.all("guest.remark").value.length<1){
			      alert('“备 注”不能为空！');
			      return false;
		}
		guestForm.submit();
	}
</script>
</head>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td class="localTdBg">当前位置： 联系人管理 -- 添加联系人</td>
	</tr>

</table>
<my:dpimporter />
<body>
<html:form method="post" action="guest.do?method=doCreateGuest">
	<table width="98%" border="0" align="center" cellpadding="0"
		cellspacing="0" id="addFormTable">
		<tr>
			<td width="25%" id="addFormTableL">名称</td>
			<td width="75%" id="addFormTableR"><input name="guest.name"
				type="text" value="${guest.name}"><font color="#FF0000">*注意:联系人名称添加后不可以变更</font></td>
		</tr>
		<tr>
			<td width="25%" id="addFormTableL">电话</td>
			<td width="75%" id="addFormTableR"><input name="guest.tel"
				type="text" value="${guest.tel}"></td>
		</tr>
		<tr>
			<td width="25%" id="addFormTableL">课程类别</td>
			<td width="75%" id="addFormTableR"><select
				name="guest.lessonTypeId" id="guest.lessonTypeId" value="${guest.lessonTypeId}"
				onchange="test()">
				<option></option>
				<c:forEach var="lessonType" items="${lessonTypeList}">
					<option value="${lessonType.ltid }">${lessonType.name }</option>
				</c:forEach>
			</select></td>
		</tr>
		<tr>
			<td width="25%" id="addFormTableL">学校</td>
			<td width="75%" id="addFormTableR"><select name="guest.schoolId"
				id="guest.schoolId" value="${guest.schoolId}">
				<option></option>
				<c:forEach var="school" items="${schoolList}">
					<option value="${school.sid }">${school.name}</option>
				</c:forEach>
			</select> <img src="styles/image/add.GIF" onclick="javascript:addSchool();">
			</td>
		</tr>
		<tr>
			<td width="25%" id="addFormTableL">课程</td>
			<td width="75%" id="addFormTableR"><input name="guest.lesson"
				type="text" value="${guest.lesson}"></td>
		</tr>
		<tr>
			<td width="25%" id="addFormTableL">开课时间</td>
			<td width="75%" id="addFormTableR"><my:dp
				elementid="StartClassTimeId" name="guest.startClassTime"
				value="${guest.startClassTime}" canNull="true"
				format="%Y-%m-%d %H:%M:%S" showTime="true" style=""
				styleClass="formInput"></my:dp></td>
		</tr>
		<tr>
			<td width="25%" id="addFormTableL">报名与否</td>
			<td width="75%"><select name="guest.signType"
				id="guest.signType" value="${guest.signType}" onChange="changeRow()">
				<option value="0">已报名</option>
				<option value="1">未报名</option>
			</select></td>
		</tr>
		<tr>
			<td width="25%">备注</td>
			<td width="75%"></td>
		</tr>
		<tr>
			<td width="25%" id="addFormTableL"></td>
			<!-- 
		<input name="guest.remark" type="" value="${guest.remark}">
		 -->
			<td width="75%" id="addFormTableR"><textarea rows="3" cols="20"
				name="guest.remark">${guest.remark}</textarea></td>
		</tr>
		<tr>
			<td width="25%">&nbsp;</td>
			<td width="75%"><input name="Submit" type="button"
				class="formSubmit" value="提交" onclick="javascript:submitCheck()">
			<input onclick="lessonTypeForm.reset();" type="reset"
				class="formSubmit" value="重置"></td>
		</tr>
	</table>
	<div id="div1" style="display: none">
	<td width="25%" id="addFormTableL"></td>
	</div>
	<div id="div2" style="display: none">
	<td width="75%" id="addFormTableR"><select
		name="guest.otherSchoolId" id="guest.otherSchoolId">
		<c:forEach var="school" items="${schoolList}">
			<option value="${school.sid }">${school.name}</option>
		</c:forEach>
	</select> <img src="styles/image/add.GIF" onclick="addSchool();"> <img
		src="styles/image/reduce.GIF"
		onclick="deleteSchool(this.parentElement.parentElement);"></td>
	</div>
	<div id="div7" style="display: none">
	<table align="left">
		<tr>
			<td width="25%" id="addFormTableL">重要回访时间</td>
		</tr>
		<tr>
			<td width="25%" id="addFormTableL">重要度</td>
		</tr>
	</table>
	</div>
	<div id="div8" style="display: none">
	<table align="left">
		<tr>
			<td width="75%" id="addFormTableL"><input type="text"
				name="guest.returnVisitTime">天后</td>
		<tr>
		<tr>
			<td width="25%" id="addFormTableL" title="星级越高，重要度越高"><select
				name="guest.importantType">
				<%
					for (int i = 1; i < 6; i++) {
				%>
				<option value="<%=i %>"><%=i%>星</option>
				<%
					}
				%>
			</select></td>
		</tr>
	</table>
	</div>
</html:form>
</body>
</html>